package com.itheima.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;

public class StreamDemo2 {
    public static void main(String[] args) {
        //stream流的中间方法
        ArrayList<String> list =new ArrayList<>();
        Collections.addAll(list,"张无忌","张无忌", "赵敏","周芷若",
                "张翠山");
        ArrayList<String> list1 =new ArrayList<>();
        Collections.addAll(list1,"张三丰-15","黑山老妖-15");
        list.stream().filter( s-> s.startsWith("张")).forEach(s -> System.out.println(s));
        System.out.println("====================================");
        list.stream().limit(3).forEach(s -> System.out.println(s));

        System.out.println("====================================");
        list.stream().skip(3).forEach(s -> System.out.println(s));

        System.out.println("====================================");
        list.stream().distinct().forEach(s-> System.out.println(s));

        System.out.println("====================================");
        Stream.concat(list.stream(),list1.stream()).forEach(s -> System.out.println(s));

        list1.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                String[] arr = s.split("-");
                String age = arr[1];
                int i = Integer.parseInt(age);
                return i;
            }
        }).forEach(s-> System.out.println(s));
    }

}
